package com.situ.mall.common.util;

import com.situ.mall.common.entity.Member;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Stack;

public class RequestUtil {

    private  static final String CURRENT = "currentUser";
    private static  final String CURRENTMEMBER ="currentMember";

    public static HttpServletRequest getRequest(){
        return((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
    }

    public static HttpSession getSession(){
        return getRequest().getSession();
    }



    public static  void  setCurrent(Object u){
        getSession().setAttribute(CURRENT,u);
    }
    public static  void  setCurrentmember(Object u){
        getSession().setAttribute(CURRENTMEMBER,u);
    }

    public static void removeCurrent(Object u){ getSession().removeAttribute(CURRENT);}
    public static Object getCurrent(){
        return getSession().getAttribute(CURRENT);

    }

    public static Object getCurrentMember(){
        return getSession().getAttribute(CURRENTMEMBER);

    }
    //获取当前会员id
        public static  Integer getCurrentMemberId(){
            Member m = (Member) getSession().getAttribute(CURRENT);
            return m.getId();
    }

}
